package cn.micro.dc_excel.controller;


import cn.micro.dc_excel.tools.ToolsDaochu;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class girlController2 {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    public List daochu(String sql) {
        List list = jdbcTemplate.queryForList(sql);
        System.out.println(list.size());
        return list;

    }

    /**
     * 联盟管理》商家管理》待审核
     * hyb
     * status:0
     * sjgldsh.do
     */
    @RequestMapping(value = "sjgldsh.do")
    public void sjgldsh(HttpServletRequest req, HttpServletResponse res, String start, String end, String classify_one ,String merchant_name) throws Exception {
        String sql = "select * from tf_sogoapplyfor where audit_status='0'";
        if (!StringUtils.isBlank(start)) {
            sql += " and applyfor_date >= " + start + "";
        }
        if (!StringUtils.isBlank(end)) {
            sql += " and applyfor_date <= " + end + "";
        }
        if (!StringUtils.isBlank(classify_one)) {
            sql += " and classify_one <= " + classify_one + "";
        }
        if (!StringUtils.isBlank(merchant_name)) {
            sql += " and merchant_name = " + merchant_name + "";
        }
        List list = daochu(sql);
        HashMap<String, Object> map = new HashMap<>();
        map.put("0-0", "序号");
        map.put("0-1", "时间");
        map.put("0-2", "商家名称");
        map.put("0-3", "一级分类");
        map.put("0-4", "二级分类");
        map.put("0-5", "分润比例");
        map.put("0-7", "代理商账号");
        map.put("0-6", "与代理商关系");
        map.put("0-8", "状态");
        for (int i = 0; i < list.size(); i++) {
            map.put("" + (i + 1) + "-0", i);
            map.put("" + (i + 1) + "-1", ((Map) list.get(i)).get("applyfor_date"));//时间
            map.put("" + (i + 1) + "-2", ((Map) list.get(i)).get("merchant_name"));//商家名称
            map.put("" + (i + 1) + "-3", ((Map) list.get(i)).get("classify_one"));//一级分类
            map.put("" + (i + 1) + "-4", ((Map) list.get(i)).get("classify_two"));//二级分类
            map.put("" + (i + 1) + "-5", ((Map) list.get(i)).get("merchant_fenrun"));//分润比例
            String zhanghao = (String) ((Map) list.get(i)).get("applyfor_user2");
            if (zhanghao.indexOf('_') != '_') {
                System.out.println("不包含");
                map.put("" + (i + 1) + "-6", ("创客"));//代理商账号
            } else {
                System.out.println("包含");
                map.put("" + (i + 1) + "-6", ("代理商"));//代理商账号
            }
            map.put("" + (i + 1) + "-7", ((Map) list.get(i)).get("applyfor_user2"));//代理商账号
            String status = (String) ((Map) list.get(i)).get("audit_status");
            if ("1".equals(status)) {
                System.out.println("已通过");
                map.put("" + (i + 1) + "-8", ("已通过"));//状态
            } else if ("0".equals(status)) {
                System.out.println("待审核");
                map.put("" + (i + 1) + "-8", ("待审核"));//状态
            } else {
                System.out.println("已驳回");
                map.put("" + (i + 1) + "-8", ("已驳回"));//状态
            }

        }
        String xlsName = "商家管理待审核";
        ToolsDaochu.getTfAttenceListExport(req, res, xlsName, map);
    }

    /**
     * 联盟管理》商家管理》已审核
     * hyb
     * status:1
     * sjglysh.do
     */
    @RequestMapping(value = "sjglysh.do")
    public void sjglysh(HttpServletRequest req, HttpServletResponse res, String start, String end, String classify_one,String merchant_name) throws Exception {
        String sql = "select * from tf_sogoapplyfor where audit_status='1'";
        if (!StringUtils.isBlank(start)) {
            sql += " and applyfor_date >= " + start + "";
        }
        if (!StringUtils.isBlank(end)) {
            sql += " and applyfor_date <= " + end + "";
        }
        if (!StringUtils.isBlank(classify_one)) {
            sql += " and classify_one <= " + classify_one + "";
        }
        if (!StringUtils.isBlank(merchant_name)) {
            sql += " and merchant_name = " + merchant_name + "";
        }
        List list = daochu(sql);
        HashMap<String, Object> map = new HashMap<>();
        map.put("0-0", "序号");
        map.put("0-1", "时间");
        map.put("0-2", "商家名称");
        map.put("0-3", "一级分类");
        map.put("0-4", "二级分类");
        map.put("0-5", "分润比例");
        map.put("0-7", "代理商账号");
        map.put("0-6", "与代理商关系");
        map.put("0-8", "状态");
        for (int i = 0; i < list.size(); i++) {
            map.put("" + (i + 1) + "-0", i);
            map.put("" + (i + 1) + "-1", ((Map) list.get(i)).get("applyfor_date"));//时间
            map.put("" + (i + 1) + "-2", ((Map) list.get(i)).get("merchant_name"));//商家名称
            map.put("" + (i + 1) + "-3", ((Map) list.get(i)).get("classify_one"));//一级分类
            map.put("" + (i + 1) + "-4", ((Map) list.get(i)).get("classify_two"));//二级分类
            map.put("" + (i + 1) + "-5", ((Map) list.get(i)).get("merchant_fenrun"));//分润比例

            String zhanghao = (String) ((Map) list.get(i)).get("applyfor_user2");
            boolean str = zhanghao.contains("_");
            if (str) {
                map.put("" + (i + 1) + "-6", ("代理商"));//代理商账号
            } else {
                map.put("" + (i + 1) + "-6", ("代理商创客"));//代理商账号
            }
           /* String str = "abc";
            boolean status = str.contains("a");
            if(status){
                System.out.println("包含");
            }else{
                System.out.println("不包含");
            }*/


            map.put("" + (i + 1) + "-7", ((Map) list.get(i)).get("applyfor_user2"));//代理商账号
            String status = (String) ((Map) list.get(i)).get("audit_status");
            if ("1".equals(status)) {
                map.put("" + (i + 1) + "-8", ("已通过"));//状态
            } else if ("0".equals(status)) {
                map.put("" + (i + 1) + "-8", ("待审核"));//状态
            } else {
                map.put("" + (i + 1) + "-8", ("已驳回"));//状态
            }

        }
        String xlsName = "商家管理已审核";
        ToolsDaochu.getTfAttenceListExport(req, res, xlsName, map);
    }

    /**
     * 联盟管理》商家管理》已驳回
     * hyb
     * status:-1
     * sjglybh.do
     */
    @RequestMapping(value = "sjglybh.do")
    public void sjglybh(HttpServletRequest req, HttpServletResponse res, String start, String end, String classify_one,String merchant_name) throws Exception {
        String sql = "select * from tf_sogoapplyfor where audit_status='-1'";
        if (!StringUtils.isBlank(start)) {
            sql += " and applyfor_date >= " + start + "";
        }
        if (!StringUtils.isBlank(end)) {
            sql += " and applyfor_date <= " + end + "";
        }
        if (!StringUtils.isBlank(classify_one)) {
            sql += " and classify_one <= " + classify_one + "";
        }
        if (!StringUtils.isBlank(merchant_name)) {
            sql += " and merchant_name = " + merchant_name + "";
        }
        List list = daochu(sql);
        HashMap<String, Object> map = new HashMap<>();
        map.put("0-0", "序号");
        map.put("0-1", "时间");
        map.put("0-2", "商家名称");
        map.put("0-3", "一级分类");
        map.put("0-4", "二级分类");
        map.put("0-5", "分润比例");
        map.put("0-7", "代理商账号");
        map.put("0-6", "与代理商关系");
        map.put("0-8", "状态");
        for (int i = 0; i < list.size(); i++) {
            map.put("" + (i + 1) + "-0", i);
            map.put("" + (i + 1) + "-1", ((Map) list.get(i)).get("applyfor_date"));//时间
            map.put("" + (i + 1) + "-2", ((Map) list.get(i)).get("merchant_name"));//商家名称
            map.put("" + (i + 1) + "-3", ((Map) list.get(i)).get("classify_one"));//一级分类
            map.put("" + (i + 1) + "-4", ((Map) list.get(i)).get("classify_two"));//二级分类
            map.put("" + (i + 1) + "-5", ((Map) list.get(i)).get("merchant_fenrun"));//分润比例
            String zhanghao = (String) ((Map) list.get(i)).get("applyfor_user2");
            if (zhanghao.indexOf('_') != '_') {
                System.out.println("不包含");
                map.put("" + (i + 1) + "-6", ("创客"));//代理商账号
            } else {
                System.out.println("包含");
                map.put("" + (i + 1) + "-6", ("代理商"));//代理商账号
            }
            map.put("" + (i + 1) + "-7", ((Map) list.get(i)).get("applyfor_user2"));//代理商账号
            String status = (String) ((Map) list.get(i)).get("audit_status");
            if ("1".equals(status)) {
                System.out.println("已通过");
                map.put("" + (i + 1) + "-8", ("已通过"));//状态
            } else if ("0".equals(status)) {
                System.out.println("待审核");
                map.put("" + (i + 1) + "-8", ("待审核"));//状态
            } else {
                System.out.println("已驳回");
                map.put("" + (i + 1) + "-8", ("已驳回"));//状态
            }

        }
        String xlsName = "商家管理已驳回";
        ToolsDaochu.getTfAttenceListExport(req, res, xlsName, map);
    }


    /**
     * 企业管理》企业申请》
     * hyb
     * qyglsq.do
     */
    @RequestMapping(value = "qyglsq.do")
    public void qyglsq(HttpServletRequest req, HttpServletResponse res, String start, String end) throws Exception {
        String sql = "select * from tf_renhemanage where 1=1";
        if (!StringUtils.isBlank(start)) {
            sql += " and applyfor_date >= " + start + "";
        }
        if (!StringUtils.isBlank(end)) {
            sql += " and applyfor_date <= " + end + "";
        }
        List list = daochu(sql);
        HashMap<String, Object> map = new HashMap<>();
        map.put("0-0", "序号");
        map.put("0-1", "时间");
        map.put("0-2", "申请人");
        map.put("0-3", "企业名称");
        map.put("0-4", "申请人账号");
        map.put("0-5", "联系电话");
        map.put("0-6", "状态");
        for (int i = 0; i < list.size(); i++) {
            map.put("" + (i + 1) + "-0", i);
            map.put("" + (i + 1) + "-1", ((Map) list.get(i)).get("applyfor_date"));//时间
            map.put("" + (i + 1) + "-2", ((Map) list.get(i)).get("applyfor_name"));//商家名称
            map.put("" + (i + 1) + "-3", ((Map) list.get(i)).get("firm_name"));//一级分类
            map.put("" + (i + 1) + "-4", ((Map) list.get(i)).get("applyfor_account"));//二级分类
            map.put("" + (i + 1) + "-5", ((Map) list.get(i)).get("firm_tel"));//分润比例
            String status = (String) ((Map) list.get(i)).get("check_status");
            if ("1".equals(status)) {
                System.out.println("已通过");
                map.put("" + (i + 1) + "-6", ("已通过"));//状态
            } else if ("0".equals(status)) {
                System.out.println("待审核");
                map.put("" + (i + 1) + "-6", ("待审核"));//状态
            } else {
                System.out.println("已驳回");
                map.put("" + (i + 1) + "-6", ("未通过"));//状态
            }

        }
        String xlsName = "企业申请";
        ToolsDaochu.getTfAttenceListExport(req, res, xlsName, map);
    }


}
